/**
 * 
 */
package scriptrunner.execution;

import java.io.Serializable;

/**
 * @author Administrator
 * 
 */
public class EvalArrayAccessExpr extends EvaluateExpr implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6645491212780189927L;

	/**
	 * 
	 */
	public EvalArrayAccessExpr(EvaluateExpr eeArray, EvaluateExpr eeIdx) {
		this.eeArray = eeArray;
		this.eeIdx = eeIdx;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * scriptrunner.execution.EvaluateExpr#CalculateResult(scriptrunner.execution
	 * .Session)
	 */
	@Override
	public ValueObject CalculateResult(Session se) throws ExecuteErrorException {
		// TODO Auto-generated method stub
		ValueObject arrayObject = eeArray.CalculateResult(se);
		ValueObject idxObject = eeIdx.CalculateResult(se);

		if (!(arrayObject instanceof ValueListObject))
			throw (new ExecuteErrorException("The variable is not a list"));

		return ((ValueListObject) arrayObject).GetListElement(idxObject);
	}

	EvaluateExpr eeArray, eeIdx;
}
